package com.persondemo.videoappliction.ui.welcome.presenter;

import com.persondemo.videoappliction.bean.GooleAdBean;
import com.persondemo.videoappliction.bean.SplashBean;
import com.persondemo.videoappliction.database.ChannelDao;
import com.persondemo.videoappliction.net.BaseApi;
import com.persondemo.videoappliction.net.BaseObserver;
import com.persondemo.videoappliction.net.RxSchedulers;
import com.persondemo.videoappliction.ui.base.BaseContract;
import com.persondemo.videoappliction.ui.base.BasePresenter;
import com.persondemo.videoappliction.ui.welcome.contract.WelcomeContract;
import com.persondemo.videoappliction.utils.T;

import javax.inject.Inject;

/**
 * Created by Administrator on 2018/4/4.
 */

public class WelcomPresenter extends BasePresenter<WelcomeContract.View> implements WelcomeContract.Presenter {
    private BaseApi baseApi;

    @Inject
    public WelcomPresenter(BaseApi baseApi) {
        this.baseApi = baseApi;
    }

    @Override
    public void getdata() {
//        SplashBean splashBean = new SplashBean();
//        splashBean = ChannelDao.getdata();
//        if (splashBean != null) {
//            mView.loadlogo(splashBean);
//        } else {
        baseApi.getlogo()
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(new BaseObserver<SplashBean>() {
                    @Override
                    public void onSuccess(SplashBean splashBean) {
                        mView.loadlogo(splashBean);
//                            if (splashBean != null && splashBean.getStatus() == 1) {
//                                ChannelDao.savesplash(splashBean);
//                            }
                    }

                    @Override
                    public void onFail(Throwable e) {
                        mView.showFaild();
                    }
                });
    }

    @Override
    public void getad() {
        baseApi.getad()
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(new BaseObserver<GooleAdBean>() {
                    @Override
                    public void onSuccess(GooleAdBean gooleAdBean) {
                        mView.load(gooleAdBean);
                    }

                    @Override
                    public void onFail(Throwable e) {
                        mView.showFaild();
                    }
                });
    }
//    }
}
